# 简单工厂模式

class Operation:
    def GetResult(self):
        pass


class OperationAdd(Operation):
    def GetResult(self):
        return self.op1 + self.op2


class OperationSub(Operation):
    def GetResult(self):
        return self.op1 - self.op2


class OpeationMul(Operation):
    def GetResult(self):
        return self.op1 * self.op2


class OperationDiv(Operation):
    def GetResult(self):
        try:
            result = self.op1 / self.op2
            return result
        except:
            print("error:divided by zero:")
            return 0


class OperationUndef(Operation):
    def GetResult(self):
        print("error:divided by zero.")
        return 0


class OperationFactory:
    operation = {} #字典
    operation["+"] = OperationAdd()
    operation["-"] = OperationSub()
    operation["*"] = OpeationMul()
    operation["/"] = OperationDiv()

    def createOperation(self, ch):
        if ch in self.operation:
            op = self.operation[ch]
        else:
            op = OperationUndef()
        return op


if __name__ == "__main__":
    op = input("Operator:")
    opa = input("a:")
    opb = input("b")
    factory = OperationFactory()
    cal = factory.createOperation(op)
    cal.op1 = int(opa)
    cal.op2 = int(opb)
    print(cal.GetResult())


"""
这里的cal.op1并没有提示。z'x
"""